package com.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

@Aspect
@Component
@EnableAspectJAutoProxy
public class LogAop {

    //定义切入点 开始方法拦截的入口
    @Pointcut("execution(* com.service..*.*(..))")
    public void logAop(){

    }

    @Before("logAop()")
    // 前置通知
    public void doBefore(){
        System.out.println("Before");
    }

    @After("logAop()")
    // 后置通知
    public void doAfter(){
        System.out.println("After");
    }

    @AfterReturning("logAop()")
    public void doAfterReturning(JoinPoint joinPoint){
        System.out.println("AfterReturning");
    }

    @AfterThrowing("logAop()")
    public void doAfterThrowing(JoinPoint joinPoint){
        System.out.println("AfterThrowing");
    }

    @Around("logAop()")
    public void doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕前");
        // 执行目标方法
        joinPoint.proceed();
        System.out.println("环绕后");
    }

}
